<?php include('header.php');?>
<?php
$group_id = $_GET['id'];

if($_GET['action']=='edit') {

	if($_POST["group_name"]!="" && $_POST["group_id"]!= ""){

		$Query = mysql_query("SELECT group_detail_name FROM group_detail WHERE group_detail_name = '".$_POST["group_name"]."' ");
		$Num = mysql_num_rows($Query);
		if($Num>='1'){
			$save = $_POST["group_name"]." มีอยู่แล้วกรุณาใช้ชื่ออื่นค่ะ";
			$group_name = $_POST['group_name'];
			$group_id = $_POST["group_id"];
		} else {
			$QueryAdd = mysql_query("UPDATE group_detail SET group_detail_name = '".$_POST["group_name"]."' WHERE group_detail_id = '".$_POST['group_id']."' ");
			if($QueryAdd){
				$save = "<script>window.location='group_manage.php'</script>";
			}
		}
	}
}

	$Query = mysql_query("SELECT * FROM group_detail WHERE group_detail_id = '".$_GET["id"]."' ");
	$Row = mysql_fetch_array($Query);
?>
<body>
<form action="?action=edit" name="formedit" method="post" id="formedit">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading">
      <h1>แก้ไขชื่อบริษัททัวร์</h1>
      <div class="buttons"><a onclick="chk_form('formedit');" class="button"><span>บันทึก</span></a><a onclick="location = 'group_manage.php';" class="button"><span>ยกเลิก</span></a></div></div>
  <div class="content">
    <table class="form">
       <tr>
        <td>ชื่อบริษัททัวร์ : </td>
        <td><input name="group_name" type="text" id="group_name" maxlength="100" value="<?php if($group_name==""){ echo $Row['group_detail_name'];} else {echo $group_name;} ?>" /><input type="hidden" name="group_id" value="<?php echo $group_id; ?>"/></td>
      </tr>
    </table>
	<?php echo "<br><font color=\"red\"><center>$save</center></font>"; ?>
  </div>
</div>
</form>
<?php mysql_close(); ?>
</body>
</html>
